/*   
 * Copyright 2011-2012 the original author or authors.   
 *   
 * Licensed under the Apache License, Version 2.0 (the "License");   
 * you may not use this file except in compliance with the License.   
 * You may obtain a copy of the License at   
 *   
 *      http://www.apache.org/licenses/LICENSE-2.0   
 *   
 * Unless required by applicable law or agreed to in writing, software   
 * distributed under the License is distributed on an "AS IS" BASIS,   
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
 * See the License for the specific language governing permissions and   
 * limitations under the License.   
 */
package code.google.com.p.antigovframe.sample

import junit.framework.*; 

import groovy.mock.interceptor.StubFor

import org.junit.*
import org.orda.sample.dao.*;
import org.hibernate.SessionFactory
import org.hibernate.Session

import code.google.com.p.antigovframe.sample.domain.Task;


/**
 * Test Case for Task Entity. <br />
 * 
 * @author Jacob
 * @since 2012. 7. 14.
 * 
 */ 
//TDD: The test class derived from GroovyTestCase may be executed in  JUnit
class TaskTest extends BaseDTOTest<Task> {  
	private String testName; 
	
	void setUp() {
		super.setUp();
	 
	}
	
	//TDD: The Task has a life cycle. But the status of a task changes can be edited by user.
	//TDD: The status follows to events performed by users or the application itself.	
	void testStatus() {
		def task1=new Task("System", "2012-07-13");
		task1.title="Task must be editable!"
		task1.body="The Task has a life cycle. But the status of a task changes is edited by user."
		task1.taskNo="TA-12345"
		task1.assignedTo="Tomy"
		task1.status="opened"
	}
		
	//TDD: TaskNo is not null
	void testConstraints () {
		def task1=new Task("System", "2012-07-13"); 
		
		def violations=checkValidated(task1);
		assert violations.size()==3; 
		
		//Mandatory Properties
		['status','taskNo','title'].each {
			mustViolating(it); 
		} 
		
		task1.title="1"
		checkValidated(task1); //recheck validation
		
		// Check the size of properties
		['title'].each {
			mustNullViolating(it);
		}
		
		
		task1.assignedTo="mail.for.me"
		checkValidated(task1);
		
		// Check the pattern of properties
		['assignedTo'].each {
			mustMatchPattern(it);
		}
		 
//		println violations.keySet().grep("status")
//		println violations.status
//		
//		violations.keySet().any {
//			println  it.getClass() 
//			println violations.get(it);
//		}
//		println violations.containsKey("taskNo");
//		assertNotNull violations.grep('status');  
//		
//		assertFalse isValid(task1);
//		
	} 
}
